#include <iostream>
#include <cstdio>
#include <string>
#include <unistd.h>
#include <pthread.h>

void* thread_routine(void* args)
{
    std::string name = (const char*)(args);
    while(true)
    {
        //新线程执行流
        std::cout << "我是新线程: " << name << "; pid: " << getpid() << std::endl;
        sleep(2);
    }
}

int main()
{
    //创建新线程
    pthread_t tid;
    pthread_create(&tid, nullptr, thread_routine, (void*)"thread-1");

    //主线程执行流
    while(true)
    {
        printf("我是主线程, pid: %d\n", getpid());
        sleep(1);
    }

    return 0;
}